package com.home.andromotic;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class ActividadAgregarPerfil extends Activity {

	private AndromoticDbHelper dBHelper;
	private AndromoticProfile profile;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_agregar_perfil);
		dBHelper = new AndromoticDbHelper(getApplicationContext());
		profile = new AndromoticProfile();

//		ListView listView = (ListView) findViewById(R.id.perfil_activity_component_list);
//		String[] values = new String[] { "Iluminacion", "Control",
//				"Entretenimiento" };
//		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
//				android.R.layout.simple_list_item_1, android.R.id.text1, values);
//		listView.setAdapter(adapter);
//
//		/* Listener */
//		listView.setOnItemClickListener(new OnItemClickListener() {
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view,
//					int position, long id) {
//				Toast.makeText(getApplicationContext(),
//						"Click ListItem Number " + position, Toast.LENGTH_LONG)
//						.show();
//				// profile.setType(position);
//			}
//		});

		Button aceptar = (Button) findViewById(R.id.perfil_activity_btn_guardar);
		aceptar.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				profile.setNombre(((EditText) findViewById(R.id.perfil_activity_edit_perfil))
						.getText().toString());
				profile.setCreador(((EditText) findViewById(R.id.perfil_activity_edit_user))
						.getText().toString());
				profile.setId(0); // TODO: escoger grupos
				dBHelper.setProfile(profile);
				Log.v("AGREGANDO PERFIL", "profile: " + profile.getNombre());
				finish();
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
